<?php
$ajaxFormSubmit = <<<EOF
$('form#{$form->id}').on('beforeSubmit', function(){
    var form = $(this);
    $.ajax({
       url: form.attr('action'),
       type: 'post',
       data: form.serialize(),
       beforeSend: function() {
           //$(':submit').html('正在提交...');
           $(':submit').attr('disabled', true);
       },
       complete: function() {
           //$(':submit').html('提交');
           $(':submit').removeAttr('disabled');
       },
       error: function() {
           showModelMessage("warning","操作失败",data.msg);
       },
       success: function(data){
           if(data.state==1) {
                showModelMessage("success","操作成功",data.msg,data.url);
                return;
           }
           if (data.state==0) {
                showModelMessage("warning","操作失败",data.msg,data.url);
                return;
           }
           console.log(data);
       }
    })
}).on('submit', function(e){
    e.preventDefault();
});
EOF;
$this->registerJs($ajaxFormSubmit);